const SESSION = window.sessionStorage;
const STROAGE = window.localStorage;

export function getSession(key: string) {
  const wxt = SESSION.getItem(key);
  if (wxt) {
    return JSON.parse(wxt).data;
  }
  return false;
}

export function setSession(key: string, obj: any) {
  interface objc {
    data: any;
  }
  const data: objc = { data: {} };
  data.data = obj;
  SESSION.setItem(key, JSON.stringify(data));
}

export function getStorage(key: string) {
  const wxt = STROAGE.getItem(key);
  if (wxt) {
    return JSON.parse(wxt).data;
  }
  return false;
}

export function setStorage(key: string, obj: any) {
  interface objc {
    data: any;
  }
  const data: objc = { data: obj };
  STROAGE.setItem(key, JSON.stringify(data));
}

export function remove(key: string) {
  SESSION.removeItem(key);
  STROAGE.removeItem(key);
}
